package com.example.boot_mq_produce.com.mmall;

import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;
import java.util.UUID;

/**
 * @ClassName Queue_Produce
 * @Description TODO
 * @Author wushaopei
 * @Date 2019/12/25 14:40
 * @Version 1.0
 */
@Component
public class Queue_Produce {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;


    // 触发单次投递
    public void produceMsg(){
        jmsMessagingTemplate.convertAndSend(queue,"******: "+ UUID.randomUUID().toString().substring(0,6));
    }

    // 间隔时间3秒钟定投（主启动类启动后，间隔3秒投递一次）
    @Scheduled(fixedDelay =  3000)
    public  void produceMsgScheduled(){
        jmsMessagingTemplate.convertAndSend(queue,"*******Scheduled: " + UUID.randomUUID().toString().substring(0,6));
        System.out.println("**********produceMsgScheduled send ok");
    }
}
